<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        function Star(uname, sex, age) {
            this.uname = uname;
            this.sex = sex;
            this.age = age;
        }
        //方法写在原型对象里
        Star.prototype.sing = function() {
            console.log('唱歌');
        }
        var ldh = new Star('刘德华', '男', 15);
        // 原型对象应用
        Array.prototype.sum = function() {

                var sum = 0;
                for (i = 0; i < this.length; i++) {
                    sum += this[i];
                }
                return sum;
            }
            // Array.prototype = {
            //     sum: function() {
            //         var sum = 0;
            //         for (i = 0; i < this.length; i++) {
            //             sum += this[i];
            //         }
            //         return sum;
            //     }
            // }
        var arr = [1, 2, 3];
        console.log(arr.sum());
        //父构造函数和子构造函数
        function Father(uname, age) {
            this.uname = uname;
            this.age = age;
        }

        function Son(uname, age, score) {
            Father.call(this, uname, age)
            this.score = score;
        }
        var son = new Son('刘德华', 18, 100);
        console.log(son);
    </script>
</head>

<body>

</body>

</html>